﻿#region Using

using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

using GameLogic.External;

#endregion

namespace CommunicationLibrary.TransportData
{
    [DataContract(Name = "D", IsReference = true)]
    public class Route
    {
        public Route(IRoute route)
        {
            this.StartTile = InstanceManager.Instance.GetOrAddTile(route.StartTile);
            this.EndTile = InstanceManager.Instance.GetOrAddTile(route.EndTile);
            this.Identifier = route.Identifier;
            this.UnitProgressList = route.UnitProgressList.Select(x => new KeyValuePair<Unit, float>(InstanceManager.Instance.GetOrAddUnit(x.Key), x.Value));
        }

        [DataMember(Name = "A")]
        public Tile StartTile { get; set; }

        [DataMember(Name = "B")]
        public int Identifier { get; private set; }

        [DataMember(Name = "C")]
        public IEnumerable<KeyValuePair<Unit, float>> UnitProgressList { get; private set; }

        [DataMember(Name = "D")]
        public Tile EndTile { get; private set; }
    }
}